package demo519;

import java.util.*;

public class Demo {

    public static void main(String[] args) {
        TestMap testMap = new TestMap();
        Map<String, Emp> empMap = new HashMap<>();
        Emp emp = null;
        boolean flag = true;
        Scanner scanner = new Scanner(System.in);

        while (flag) {
            System.out.println("欢迎来到员工系统");
            System.out.println("0.退出系统");
            System.out.println("1.添加员工");
            System.out.println("2.查询所有的员工");
            System.out.println("3.根据姓名查询员工");
            System.out.println("4.根据编号删除员工");
            System.out.println("5.根据编号查询员工");
            System.out.println("6.根据编号修改年龄");
            System.out.println("请选择功能");

            int n = scanner.nextInt();
            scanner.nextLine();


            switch (n) {
                case 0:
                    System.out.println("退出系统");
                    flag = false;
                    break;
                case 1:
                    System.out.println("欢迎来到员工界面");
                    System.out.println("请输入员工的编号");
                    String addNumber = scanner.nextLine();
                    System.out.println("请输入员工的姓名");
                    String addName = scanner.nextLine();
                    System.out.println("请输入员工的年龄");
                    int addAge = scanner.nextInt();
                    scanner.nextLine();

                    Emp addEmp = new Emp(addNumber, addName, addAge);
                    testMap.addEmp(empMap, addEmp);
                    System.out.println("员工添加成功");
                    break;
                case 2:
                    System.out.println("所有员工信息：");
                    for (Emp e : empMap.values()) {
                        System.out.println(e);
                    }
                    break;
                case 3:
                    System.out.println("根据姓名查询员工");
                    System.out.println("请输入员工姓名");
                    String empName = scanner.nextLine();
                    emp = testMap.findAllEmpName(empMap, empName);
                    System.out.println(emp != null ? emp : "未找到该员工");
                    break;
                case 4:
                    System.out.println("根据编号删除员工");
                    System.out.println("请输入员工编号");
                    String empNumber = scanner.nextLine();
                    testMap.deleteEmp(empMap, empNumber);
                    break;
                case 5:
                    System.out.println("根据员工编号查询");
                    System.out.println("请输入员工编号");
                    String empId = scanner.nextLine();
                    emp = testMap.findAllEmpNumber(empMap, empId);
                    System.out.println(emp);
                    break;
                case 6:
                    System.out.println("根据员工编号修改年龄");
                    System.out.println("请输入要修改的员工编号");
                    String updateNumber = scanner.nextLine();
                    System.out.println("请输入需要修改的年龄");
                    int updateAge = scanner.nextInt();
                    scanner.nextLine();

                    emp = testMap.findAllEmpNumber(empMap, updateNumber);
                    if (emp != null) {
                        testMap.updateEmp(empMap, updateAge, emp);
                    } else {
                        System.out.println("未找到该员工");
                    }
                    break;
                default:
                    System.out.println("无效的选择，请重新输入");
            }
        }
        scanner.close();
    }
}




